﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;

namespace UnityLogManager
{
    /// <summary>
    /// Author:gouzhun 
    /// Manager for logging, contains logging to file, logging to console, logging to screen function.
    /// Generally called by PLog, do not recmmend to directly use this class
    /// </summary>
    public class Logger
    {
        private static string DefaultDev = "DefaultDev";
        private static string DefaultModule = "DefaultModule";

        public static string FormatVerbose = "I [{0}]: {1}";
        public static string FormatInfo = "I [{0}]: {1}";
        public static string FormatWarn = "W [{0}]: {1}";
        public static string FormatErr = "Err [{0}]: {1}";
        public static string FormatEx = "Ex [{0}]: {1} - Message: {2}  StackTrace: {3}";
        public static string FormatFile = "\n{0}{1}\t{2}\n";



        public static bool IsEnable = true;


        public static void Log(string msg, string moduleName = null, Loglevels level = Loglevels.All)
        {
            if (!IsEnable)
            {
                return;
            }

            if (string.IsNullOrEmpty(moduleName))
            {
                moduleName = DefaultModule;
            }


            switch (level)
            {
                case Loglevels.All:
                    UnityEngine.Debug.Log(string.Format(FormatVerbose, moduleName, msg));
                    break;
                case Loglevels.Information:
                    UnityEngine.Debug.Log(string.Format(FormatInfo, moduleName, msg));
                    break;
                case Loglevels.Warning:
                    UnityEngine.Debug.Log(string.Format(FormatWarn, moduleName, msg));
                    break;
                case Loglevels.Error:
                    UnityEngine.Debug.Log(string.Format(FormatErr, moduleName, msg));
                    break;
                case Loglevels.Exception:
                    UnityEngine.Debug.Log(string.Format(FormatEx, moduleName, msg));
                    break;
                case Loglevels.None:

                    break;
            }

        } 
    }



    /// <summary>
    /// Available logging levels.
    /// </summary>
    public enum Loglevels
    {
        /// <summary>
        /// All message will be logged.
        /// </summary>
        All,

        /// <summary>
        /// Only Informations and above will be logged.
        /// </summary>
        Information,

        /// <summary>
        /// Only Warnings and above will be logged.
        /// </summary>
        Warning,

        /// <summary>
        /// Only Errors and above will be logged.
        /// </summary>
        Error,

        /// <summary>
        /// Only Exceptions will be logged.
        /// </summary>
        Exception,

        /// <summary>
        /// No logging will be occur.
        /// </summary>
        None
    }
}
